<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>选择城市</title>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link href="../../css/mui.indexedlist.css" rel="stylesheet" />
		<style>
			html,
			body {
				height: 100%;
				overflow: hidden;
			}
			.mui-bar {
				-webkit-box-shadow: none;
				box-shadow: none;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">选择城市</h1>
		</header>
		<div class="mui-content">
			<div id='list' class="mui-indexed-list">
				<div class="mui-indexed-list-search mui-input-row mui-search">
					<input type="search" class="mui-input-clear mui-indexed-list-search-input" placeholder="搜索城市">
				</div>
				<div class="mui-indexed-list-bar" id="divBar">
					
				</div>
				<div class="mui-indexed-list-alert"></div>
				<div class="mui-indexed-list-inner">
					<div class="mui-indexed-list-empty-alert">没有数据</div>
					<ul class="mui-table-view" id="ulCitys">


					</ul>	
				</div>
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/mui.indexedlist.js"></script>
		<script src="../../js/vue.min.js"></script>
		<script src="../../js/tools.js"></script>
		
<script>

	function MyCitys()
	{
	  	var rsLets = [];
	  	function loadCityData(p_data)
		{
			var strHtml = '';
			var strLets = '';
			for(var i=0;i<rsLets.length;i++)
			{
				strLets += ('<a>'+rsLets[i].alet+'</a>\n');
				strHtml += ('<li data-group="'+rsLets[i].alet+'" class="mui-table-view-divider mui-indexed-list-group">'+rsLets[i].alet+'</li>\n');
				var strCurLet = rsLets[i].alet;
				var jsnAry = [];
				//for (j = 0; j < p_data.length; j++) 
				for (j = 0; j < p_data.length; j++) 
				{
					if(strCurLet == p_data[j].py.substring(0,1))
					{	
						var strPy = p_data[j].py;
						strHtml += ('<li data-value="'+p_data[j].areacode+'" data-tags="'+strPy+'" class="mui-table-view-cell mui-indexed-list-item" onclick="javascript:getCityCode(\'' + p_data[j].areacode + '\')">' + p_data[j].areaname + ',' + p_data[j].provname + '</li>\n');
						//console.log("areacode="+p_data[j].areacode);
					}
				}
				//rsLets[i].citys = jsnAry;
			}
			//debugger;
			document.getElementById("ulCitys").innerHTML = strHtml;
			document.getElementById("divBar").innerHTML = strLets;
		 }
		
		function getCityData()
	  	{
			var jData = {
				CityId:"cn"
			};
			//g_jsonData.putData("g_citys",null);
			var retCitys = g_jsonData.getData("g_citys");
			
			//alert(retCitys);
			if(retCitys == null || retCitys == "")
			{
				genpost('/zdm/AppApi/Search/CityList',
					jData,
					function(data)
					{
						g_jsonData.putData("g_citys",data);
						loadCityData(data);
					}
				);
			}
			else
			{
				loadCityData(retCitys);
			}
		}
	  	
	  	this.getAllLets=function()
  	  	{
  	  		rsLets = 
  	  			[
  	  				{alet:"a"},{alet:"b"},{alet:"c"},{alet:"d"},
  	  				{alet:"e"},{alet:"f"},{alet:"g"},{alet:"h"},
  	  				{alet:"i"},{alet:"j"},{alet:"k"},{alet:"l"},
  	  				{alet:"m"},{alet:"n"},{alet:"o"},{alet:"p"},
  	  				{alet:"q"},{alet:"r"},{alet:"s"},{alet:"t"},
  	  				{alet:"u"},{alet:"v"},{alet:"w"},{alet:"x"},
  	  				{alet:"y"},{alet:"z"}
  	  			];
  	  		
  	  		getCityData();
  	  	}
  	  	
	  }
	  
	  (new MyCitys()).getAllLets();
	  
	  function getCityCode(p_cityCode)
	  {//alert(p_cityCode);
	  		var jsnCity = null;
	  		var retCitys = g_jsonData.getData("g_citys");
	  		if(retCitys == null)
	  		{
	  			mui.toast("城市数据缺少，请登录刷新");
	  			mui.back();
	  			return;
	  		}
	  		
	  		for(var i=0;i<retCitys.length;i++)
	  		{
	  			if(p_cityCode == retCitys[i].areacode)
	  			{
	  				jsnCity = retCitys[i];
	  				break;
	  			}
	  		}
	  		//alert(g_jsonData.getData("retUrl"));
	  		var main = plus.webview.getWebviewById(g_jsonData.getData("retUrl"));
			mui.fire(main,'gotmsg',{msg:'setcity',curCity:jsnCity});
			mui.back();
	  }

	</script>
		
		<script type="text/javascript" charset="utf-8">
			mui.init();
			mui.ready(function() {
				
				var header = document.querySelector('header.mui-bar');
				var list = document.getElementById('list');
				//calc hieght
				list.style.height = (document.body.offsetHeight - header.offsetHeight) + 'px';
				//create
				window.indexedList = new mui.IndexedList(list);
				//mui("#list").indexedList().findElements();
				
			});
		</script>
	</body>

</html>